package com.yuan.hospital.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuan.hospital.common.exception.EduException;
import com.yuan.hospital.common.result.ResultCodeEnum;
import com.yuan.hospital.mapper.HospitalSetMapper;
import com.yuan.hospital.service.HospitalSetService;
import com.yuan.model.hospital.HospitalSet;
import com.yuan.vo.order.SignInfoVo;
import org.springframework.stereotype.Service;

@Service
public class HospitalSetServiceImpl extends ServiceImpl<HospitalSetMapper, HospitalSet> implements HospitalSetService {
    /**
     * 根据医院编码取医签名
     *
     * @param hospitalCode 医院编码
     * @return
     */
    @Override
    public String getSignKey(String hospitalCode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new LambdaQueryWrapper<HospitalSet>().eq(HospitalSet::getHoscode
                , hospitalCode));
        return hospitalSet.getSignKey();
    }

    /**
     * 根据医院编码获取医院签名信息
     *
     * @param hospitalCode 医院编码
     * @return
     */
    @Override
    public SignInfoVo getSignInfoVo(String hospitalCode) {
        HospitalSet hospitalSet = baseMapper.selectOne(new LambdaQueryWrapper<HospitalSet>().eq(HospitalSet::getHoscode
                , hospitalCode));
        if (hospitalSet == null) {
            throw new EduException(ResultCodeEnum.HOSPITAL_OPEN);
        }
        SignInfoVo signInfoVo = new SignInfoVo();
        signInfoVo.setApiUrl(hospitalSet.getApiUrl());
        signInfoVo.setSignKey(hospitalSet.getSignKey());
        return signInfoVo;
    }
}
